home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / ARTAbrot 1.21 / MBROT.S < prev    next >
Encoding:
Text File  |  1994-12-08  |  6.4 KB  |  186 lines  |  [TEXT/MPS ]

  1. tputData.    */
  2. /*            Program completes by writing a nonzero value to Doneflag.    */
  3. /*                                                                        */
  4. /*    REVISIONS:                                                            */
  5. /*    10/22/93    GTW    Increased maximum line length to 1280 pixels.        */
  6. /*    08/22/93    GTW    Converted from VCOS to ARTA code.                    */
  7. /*    02/14/92    GTW    Cleaned up.                                            */
  8. /*    12/23/91    GTW    First working DSP3210 version.                        */
  9. /*                                                                        */
  10. /************************************************************************/
  11.  
  12. #include "DSP3210.h"
  13.  
  14. /* Macro for PC relative addressing. */
  15. #define AddressPR(LAB) pc + LAB - (.+8)
  16.  
  17. NewModule(MBrot, kdspSmoothModule, kdspAutoCache, cmain)
  18.     long    100, 4, 655        /* I don't know about this. */
  19.  
  20. NewCachedProgramSection(cmain, MBrot)
  21. NewParameterSection(brobuf, kdspAppSpecificData, MBrot)
  22.  
  23. AppendSection(cmain)
  24.     *sp++ = r5
  25.     *sp++ = r6
  26.     *sp++ = r8
  27.     *sp++ = r10
  28.     *sp++ = r11
  29.     *sp++ = r13
  30.     *sp++ = r14
  31.     *sp++ = r18                    /* Push r18 onto stack. */
  32.  
  33.     GetSectionAddress(r5, brobuf)    /* Get address for brobuf and put in r5.    */
  34.     /* Once I get the section base address in a register (r5), I can make all    */
  35.     /* future accesses by register relative addressing.                            */
  36.  
  37.     r2 = r5 + (Inited - Startflag)        // r2 = Inited
  38.  
  39.     r1 = *r2
  40.     nop
  41.     if(ne) pcgoto Wait_for_go    /* Go ahead if initialized. */
  42.     r1 = (short) 1
  43.  
  44.     r3 = r5 + (Startflag - Startflag)        // r3 = Startflag
  45.     *r3 = r0                    /* Clear startflag. */
  46.     r4 = r5 + (Doneflag - Startflag)        // r4 = Doneflag
  47.     *r4 = r0                    /* Clear doneflag. */
  48.     *r2 = r1                    /* Set inited flag. */
  49.  
  50. Wait_for_go:
  51.     r4 = r5 + (Startflag - Startflag)        // r4 = Startflag
  52.     r3 = *r4
  53.     nop
  54.     if(eq) pcgoto exit            /* Be a "good citizen" and return. */
  55.     nop
  56.  
  57.     *r4 = r0                    /* Clear Startflag. */
  58.  
  59.     r13 = r0                    /* Zero point counter. */
  60.     r10 = r5 + (OutputData - Startflag)        // r10 = OutputData            /* Set pointer to output data. */
  61.     r14 = r5 + (Maxiter - Startflag)        // r14 = Maxiter
  62.     r14 = *r14                    /* Get the maximum number of iterations. */
  63.     r8 = AddressPR(Scrfl)                    /* Set pointer to temp storage. */
  64.     
  65.     r2 = r5 + (Xstart - Startflag)        // r2 = Xstart                    /* Convert IEEE format. */
  66.     r3 = AddressPR(myXstart)
  67.     /* Use these to convert from IEEE to DSP3210 format. */
  68.     *r3++ = a0 = dsp(*r2++)
  69.     *r3++ = a0 = dsp(*r2++)
  70.     *r3 = a0 = dsp(*r2)
  71.                                 /* Compute y coordinate. */
  72.     /* r11 - iteration count. */
  73.     /* r13 - point counter. */
  74.     /* r14 - max iterations. */
  75.     /* r8  - pointer to temp storage. */
  76. Mloop:
  77.     r2 = AddressPR(Scrlong)        /* Set pointer to temp storage. */
  78.     *r2 = r13                    /* Store in memory. */
  79.     r3 = AddressPR(myDelta)        /* Set pointer to delta x. */
  80.     a0 = float32(*r2)            /* Convert count to floating point. */
  81.     r6 = AddressPR(myXstart)    /* Set pointer to base x. */
  82.     r11 = AddressPR(Zero)
  83.     a2 = *r6 + a0 * *r3            /* Coordinate=base+(pointnum * deltaX) */
  84.     r3 = AddressPR(myYstart)
  85.     a3 = *r3                    /* Get imaginary cooridinate (y). */
  86.     a0 = *r11                    /* Zero the accumulator. */
  87.     a1 = *r11                    /* Zero the accumulator. */
  88.     *r8++ = a2 = a2                /* Save real c. */
  89.     *r8-- = a3 = a3                /* Save imaginary c. */
  90.     r11 = r0                    /* Zero iteration count. */
  91.  
  92. Mandel: 
  93.     pccall TestMag(r18)
  94.     r11 = r11 + 1                /* Increment iteration count. */
  95.  
  96.     if(ne) pcgoto Pointdone        /* This point diverged; it's done. */
  97.     nop
  98.  
  99.     r11 - r14                    /* Compare to max. num. of iterations. */
  100.     if(ge) pcgoto Pointdone        /* Return if greater than or equal to. */
  101.     nop
  102.  
  103.  
  104.     /* Now the famous z = z^2 + C function */
  105. DoTheBrot:
  106.     a2 = a0 * a1
  107.     a3 = a0 * a0
  108.     a0 = a3 - a1 * a1            /* This gives the real part of z squared. */
  109.     a1 = a2 + a2                /* This gives the imaginary part of z squared. */
  110.     a0 = a0 + *r8++                /* This is the +C (real) part of the equation. */
  111.     pcgoto Mandel
  112.     a1 = a1 + *r8--                /* This is the +C (img.) part of the equation. */
  113.  
  114. Pointdone:
  115.     *r10++ = (short)r11            /* Save result. */
  116.     r2 = r5 + (Points - Startflag)        // r2 = Points
  117.     r2 = *r2                    /* Get the number of points to do. */
  118.     r13 = r13 + 1
  119.     r2 - r13                    /* Are there more points to do? */
  120.     if(gt) pcgoto Mloop            /* If so, go do next point. */
  121.     nop 
  122.  
  123. Linedone:
  124.     r14 = (short)0x69            /* Just an arbitrary non-zero number. */
  125.     r4 = r5 + (Doneflag - Startflag)    // r4 = Doneflag
  126.     *r4 = r14                    /* Indicate that DSP is done. */
  127.  
  128. exit:
  129.     r4 = sp - 4
  130.     r18 = *r4--                    /* Pull r18 off stack. */
  131.     r14 = *r4--                    /* Pull r14 off stack. */
  132.     r13 = *r4--                    /* Pull r13 off stack. */
  133.     r11 = *r4--                    /* Pull r11 off stack. */
  134.     r10 = *r4--                    /* Pull r10 off stack. */
  135.     r8 = *r4--                    /* Pull r8 off stack. */
  136.     r6 = *r4--                    /* Pull r6 off stack. */
  137.     r5 = *r4--                    /* Pull r5 off stack. */
  138.     sp = sp - 32                /* Restore stack pointer. */
  139.     return(r18)
  140.     nop
  141.  
  142. /************************************************************************/
  143. /* TestMag -- subroutine to compare magnitude of complex number in a0    */
  144. /*        and a1 to 2.0.  If greater, r1 = 1 upon exiting; if                */
  145. /*        less, r1 = 0.                                                    */
  146. /************************************************************************/
  147. TestMag:
  148.     a3 = a0 * a0                /* Square real part. */
  149.     a3 = a3 + a1 * a1            /* Add to img. part squared. */
  150.     r2 = AddressPR(Four)
  151.     a3 = a3 - *r2                /* Compare to 4.0. */
  152.     nop
  153.     nop
  154.     nop
  155.     if(alt) pcgoto Donef        /* If negative result, goto Done. */
  156.     r1 = r0
  157.     r1 = (short)1                /* Result did not diverge. */
  158. Donef:
  159.     return(r18)
  160.     r1 - 0                        /* Set flags based on result. */
  161.  
  162. Four:        float 4.0            /* Number for magnitude comparisons. */
  163. Zero:        float 0.0
  164. Scrfl:        2 * float            /* Scratch pad. */
  165. Scrlong:    long                /* Scratch pad. */
  166. myXstart:    float    0.0
  167. myDelta:    float    0.0
  168. myYstart:    float    0.0
  169.  
  170.  
  171. AppendSection(brobuf)
  172. /* Note: Xstart, Delta, and Ystart all hold IEEE representations of    */
  173. /* floating point values.  Hence, they have been declared as longs    */
  174. /* in order that they not be confused with DSP floats.                */
  175.  
  176. Startflag:    int        0
  177. Doneflag:    int        0
  178. Points:        long    640        /* Number of points. */
  179. Maxiter:    long    63        /* Maximum number of iterations. */
  180. Xstart:        long    80        /* Starting real (x) coordinate. */
  181. Delta:        long    80        /* Delta x. */
  182. Ystart:        long    80        /* y coordinate. */
  183. Inited:        long    0        /* Initialization flag. */
  184. OutputData:
  185.             1280 * short
  186.